package club.guadazi.wemarket.service.impl;

import club.guadazi.wemarket.dao.OrderSimpleMapper;
import club.guadazi.wemarket.entity.OrderSimpleInfo;
import club.guadazi.wemarket.service.OrderSimpleService;
import club.guadazi.wemarket.util.excel.ExcelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * Created by Mariaaron on 2016/11/5.
 */
@Service("orderSimpleService")
public class OrderSimpleServiceImpl implements OrderSimpleService {
    @Autowired
    private OrderSimpleMapper orderSimpleMapper;

    @Override
    public List<OrderSimpleInfo> searchLikeName(String name) {
        List<OrderSimpleInfo> orderSimpleInfos = orderSimpleMapper.findLikeByUsername(name);
        return orderSimpleInfos;
    }

    @Override
    public List<OrderSimpleInfo> listAll() {
        List<OrderSimpleInfo> orderSimpleInfos = orderSimpleMapper.listAll();
        return orderSimpleInfos;
    }

    @Override
    public List<OrderSimpleInfo> listAllLike(OrderSimpleInfo orderSimpleInfo) {
        List<OrderSimpleInfo> orderSimpleInfos = orderSimpleMapper.listAllLike(orderSimpleInfo);
        return orderSimpleInfos;
    }

    @Override
    public List<OrderSimpleInfo> importOrderSimpleInfos(MultipartFile file) throws IOException, InstantiationException, IllegalAccessException {
        InputStream inputStream = file.getInputStream();
        List<OrderSimpleInfo> orderSimpleInfos = ExcelUtils.read(inputStream, OrderSimpleInfo.class);

        int id = orderSimpleMapper.insertBatch(orderSimpleInfos);
        return orderSimpleInfos;
    }
}
